package pool;

import java.util.ArrayList;
import java.util.List;

import pool.model.DefaultCar;
import pool.model.ICar;
import pool.properties.MyProperties;

public class CarPool {

	private List<ICar> allCars;

	private int poolSize;

	private String handlerType;

	/*
	 * There should be only one CarPool per application
	 * Implemented as Singleton
	 */
	private static CarPool instance = null;
	
	private MyProperties myProperties;
	
	
	private CarPool() {
		init();
	}

	public static CarPool getInstance() {

		if (instance == null) {
			instance = new CarPool();
		}

		return instance;
	}

	public ICar getCar() {
		// TODO Auto-generated method stub
		return null;
	}

	public void releaseCar(ICar car) {
		car.setInUse(false);
		System.out.println(car + "released!");
	}
	
	/**
	 * @return true - success
	 */
	private void init(){
		
		allCars = new ArrayList<ICar>();
		myProperties = new MyProperties("config");

		poolSize = Integer.parseInt(myProperties.getProperty("pool.size"));
		handlerType = myProperties.getProperty("handler.type");

		//Initialize pool
		for(int i=0; i<poolSize; i++){
			allCars.add(new DefaultCar("KRK"+i));
		}
	}
}
